<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "zs_contactor_cat".
 *
 * @property integer $id
 * @property integer $cat_id
 * @property integer $contactor_id
 */
class ContactorCat extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'zs_contactor_cat';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cat_id', 'contactor_id'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cat_id' => '分类id',
            'contactor_id' => '联系人id',
        ];
    }

    public static function getCatNameByContactId($cid = 0)
    {

        $data = self::findAll(['contactor_id' => $cid]);
        if(empty($data)){
            return '';
        }
        $result = '';
        foreach($data as $v){
            $cat_name = CustomerCat::getNameById($v->cat_id);

            $result = $result .$cat_name.' ';
        }

        return $result;
    }
}
